Tryit Editor v2.3

Edit This Code:
<!DOCTYPE html> <html> <body> <p>Click the button to create a SECTION element containing a H1 and P element.</p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { var x = document.createElement("SECTION"); x.setAttribute("id", "mySection"); document.body.appendChild(x); var heading = document.createElement("H1"); var txt1 = document.createTextNode("Section Heading"); heading.appendChild(txt1); document.getElementById("mySection").appendChild(heading); var para = document.createElement("P"); var txt2 = document.createTextNode("Some text in section.."); para.appendChild(txt2); document.getElementById("mySection").appendChild(para); } </script> </body> <!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_section_create by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 23 Jan 2015 08:05:05 GMT --> </html>
Result:
Try it Yourself - © w3schools.com